package org.processor;

import java.util.StringTokenizer;

public class TypeReference {

	private final String qualifiedName;
	private final String simpleName;
	private final String packageName;
	private final boolean nativeType;
	private final boolean defaultPackage;
	
	public TypeReference(String qualifiedName, String simpleName,
			String packageName, boolean nativeType, boolean defaultPackage) {
		super();
		this.qualifiedName = qualifiedName;
		this.simpleName = simpleName;
		this.packageName = packageName;
		this.nativeType = nativeType;
		this.defaultPackage = defaultPackage;
	}

	public String getQualifiedName() {
		return qualifiedName;
	}

	public String getSimpleName() {
		return simpleName;
	}

	public String getPackageName() {
		return packageName;
	}
	
	public boolean isNativeType() {
		return nativeType;
	}

	public boolean isDefaultPackage() {
		return defaultPackage;
	}

	private String[] splitClassName(String qualifiedName) {
		StringTokenizer tokenizer = new StringTokenizer(qualifiedName,".");
		StringBuilder packageName = new StringBuilder();
		StringBuilder className = new StringBuilder();
		while (tokenizer.hasMoreElements()) {
			String token = tokenizer.nextToken();
			if (Character.isUpperCase(token.charAt(0))) {
				className.append(token);
				if (tokenizer.hasMoreElements()) {
					className.append(".");
				}
			} else {
				packageName.append(token);
				if (tokenizer.hasMoreElements()) {
					packageName.append(".");
				}
			}
		}
		if (className.length() == 0) {
			// no class name. it is a native type
			return new String[] {null, packageName.toString()};
		} else if (packageName.length() == 0) {
			// class in default package.
			return new String[] {null, packageName.toString()};
		}
		return new String[]{packageName.toString(), className.toString()};
		
	}
	
}
